//
//  ViewController.swift
//  PeggyTest
//
//  Created by Peggy on 17/6/5.
//  Copyright © 2017年 Peggy. All rights reserved.
//

import UIKit

class ViewController: UIViewController ,UITableViewDelegate,UITableViewDataSource{
    
    
    var user1 = User.init()
    var user2 = User.init()
    var user3 = User.init()
    var user4 = User.init()
    var user5 = User.init()


    @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.tableView.register(UINib.init(nibName: "Cell", bundle: nil), forCellReuseIdentifier: "Cell")
        self.tableView.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: "cell")
        self.getDate()
       
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 5;
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        switch indexPath.row {
        case 0:
            let cell:Cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! Cell
            cell.user = self.user1
            return cell;
        case 1:
            let cell:Cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! Cell
            cell.user = self.user2

            return cell;
        case 2:
            let cell:Cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! Cell
            cell.user = self.user3

            return cell;
        case 3:
            let cell:Cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! Cell
            cell.user = self.user4

            return cell;
        case 4:
            let cell:Cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! Cell
            cell.user = self.user5

            return cell;
        default:
            let customCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
            return customCell
        }
        
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 100;
    }
    
    func getDate(){
        let vm = VM.init()
        vm .getDate1()
        self.user1 = vm.user!
        
        vm .getDate2()
        self.user2 = vm.user!
        vm .getDate3()
        self.user3 = vm.user!
        vm .getDate4()
        self.user4 = vm.user!
        vm .getDate5()
        self.user5 = vm.user!
        self.tableView .reloadData()
    }

}

